<%--
  - Author		:	Jaewon Choi
  - Date			:
  - Description	:	
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<meta name="viewport" content="initial-scale=1.0,minimum-scale=1.0,maximum-scale=2.0">
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirScripts}/bxslider/jquery.bxslider.css" />" />
		<style type="text/css">
			body {
				width: 100%;
				margin: 0;
				padding: 0;
				background: #F0F0EF;
			}
			
			.rollingWrap {
				margin-top: 10px;
			}
			
			.contWrap {
				width: 360px;
				max-width: 100%;
				margin: 0 auto;
			}
			
			img {
				max-width: 100%;
			}
			.bx-wrapper {
				overflow: hidden;
				margin-bottom: 25px;
			}
			.bx-wrapper .bx-viewport {
				border: none;
				left:0;
			}
			.bx-controls {
				position: absolute;
				top: 0px;
				right: 10px;
			}
			.bx-wrapper .bx-pager {
				padding: 0;
				right: 0;
				width: 360px;
				text-align: right;
				bottom: -20px;
			}
			.bx-pager-item{
				text-align: left;
			}
			.bxslider {
				margin: 0;
			}
			.bx-wrapper .bx-pager.bx-default-pager a {
				background: #939393;
				width: 5px;
				height: 5px;
				margin: 0 3px;
			}
			default-pager a:hover, .bx-wrapper .bx-pager.bx-default-pager a.active {
				background: #1D1D1D;
			}
			
			.eventImgWrap {
				position: relative;
				width: 155px;
				height: 90px;
				float: left;
			}
			.eventImgWrap.left {
				margin: 0 20px 15px 15px; 
			}
			.eventImgWrap.right {
				margin: 0 15px 15px 0px;
			}
			.eventImg {
				width: 100%;
				height: 100%;
			}
			.emblem {
				position: absolute; 
				bottom: 0;
				right:0;
				width: 25%;
			}
			
			.detailImg {
				width: 100%;
			}
		</style>
 		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
 		<script type="text/javascript" src="<c:url value="${dirScripts}/bxslider/jquery.bxslider.js" />"></script>
		<script type="text/javascript">
		
			$(function() {
				$('.bxslider').bxSlider({
					mode: 'horizontal',
					speed: 100,
					randomStart: true,
					auto: true,
					controls:false,
					pause:3000
				});
				<c:if test="${not empty param.idx}">
					$("#detailImg${param.idx}").click();
				</c:if>
			});
			
			function detail(src, link, eventIdx){
				$(".detailImg").attr("src", src);
				$(".detailImg").click(function(){goEvent2(eventIdx, link);});
				$('.rollingWrap').hide();
				$('.listWrap').hide();
				$('.detailImg').show();
			}
			
			function goEvent(eventIdx, link){
				var data = '[{"cmd":"detailedEvent","eventIdx":'+eventIdx+',"actionTime":"now"}]';
				document.frm.data.value = data;
				
				$.ajax({
					type: "POST",
					url: "<c:url value="/API/v1_0/logUpload2" />",
					dataType: "json",
					async: false,
					data: $(document.frm).serialize(),
					success: function(data){
						if(data.returnCode == "000"){
							location.href = link;
						}else{
							alert(data.returnMessage);
						}
					},
					beforeSend: function(){
					},
					error: function(jqXHR, textStatus, errorThrown){
						//alert(jqXHR.responseText); //에러 페이지 내용
						alert("오류가 발생하였습니다.\n관리자에게 문의 바랍니다.");
						throw errorThrown;
					},
					complete: function(){
					}
				 });
				
			}
			
			function goEvent2(eventIdx, link){
				//var data = '[{"cmd":"detailedEvent","eventIdx":'+eventIdx+',"actionTime":"now"}]';
				var data = '[{"cmd":"viewLog","contIdx":37,"fileIdx":2,"actionTime":"20130425173000","logData":[{"PageIndex":"1", "ViewCount":"1", "ViewDuration":"20136548","ScrapCount":"0","EmailCount":"0","TwitterCount":"1","FacebookCount":"1"}, {"PageIndex":"1", "ViewCount":"1", "ViewDuration":"20136548","ScrapCount":"0","EmailCount":"0","TwitterCount":"1","FacebookCount":"1"}]}]';
				//var data = '[{"orderId":"data_orderid","packageName":"data_packageName","productId":"data_productId","purchaseTime" : "data_purchaseTime","purchaseState":"3","developerPayload":"data_developerPayload","purchaseToken":"data_purchaseToken"}]';
				//var data = '[{"orderId":"data_orderid","packageName":"data_packageName","productId":"data_productId","purchaseTime":"data_purchaseTime","purchaseState":"A","developerPayload":"data_developerPayload","purchaseToken":"data_purchaseToken"}]';
				var data = '[{"purchaseToken":"jiomkzpoukdncwqiiaophcph.AO-J1Oyc3Z9Avk3E6Jf0Ya6fY2BX4X_S60N-LCnEkKpU4UfzL4PcUUHhHSAj-Zb1UPu77lVyA8CiLX5UEKVvRqIYBLYkVU6NNWkrrA4tZldottB8pAkYDDhcVlrTuT1kjtd7CmUxU2BN","developerPayload":"mediastory.test@gmail.com48test_magazine_00004","packageName":"com.mediastory.umagazine","purchaseState":0,"orderId":"12999763169054705758.1341588674115242","purchaseTime":1382680559428,"productId":"test_magazine_00004"}]';
				document.frm.data.value = data;
				
				$.ajax({
					type: "POST",
					//url: "<c:url value="http://14.63.162.53:8080/u_magazine_api/API/v1_0/logUpload2" />",
					url: "<c:url value="/API/v1_0/purchaseUpload" />",
					dataType: "json",
					async: false,
					data: $(document.frm).serialize(),
					success: function(data){
						if(data.returnCode == "000"){
							location.href = link;
						}else{
							alert(data.returnCode);
							alert(data.returnMessage);
						}
					},
					beforeSend: function(){
					},
					//error: function(jqXHR, textStatus, errorThrown){
					error:function(request,status,error){
						alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
						alert("오류가 발생하였습니다.\n관리자에게 문의 바랍니다.");
						throw errorThrown;
					},
					complete: function(){
					}
				 });
				
			}
			
			
			function goEvent3(eventIdx, link){
				//var data = '[{"cmd":"detailedEvent","eventIdx":'+eventIdx+',"actionTime":"now"}]';
				//var data = '[{"cmd":"viewLog","contIdx":1,"fileIdx":2,"actionTime":"20130425173000","logData":[{"PageIndex":"1", "ViewCount":"1", "ViewDuration":"20136548","ScrapCount":"0","EmailCount":"0","TwitterCount":"1","FacebookCount":"1"}, {"PageIndex":"1", "ViewCount":"1", "ViewDuration":"20136548","ScrapCount":"0","EmailCount":"0","TwitterCount":"1","FacebookCount":"1"}]}]';
				var data = '[{"orderId":"data_orderid","packageName":"data_packageName","productId":"data_productId","purchaseTime" : "data_purchaseTime","purchaseState":"3","developerPayload":"data_developerPayload","purchaseToken":"data_purchaseToken"}]';
				//var data = '[{"orderId":"data_orderid","packageName":"data_packageName","productId":"data_productId","purchaseTime":"data_purchaseTime","purchaseState":"A","developerPayload":"data_developerPayload","purchaseToken":"data_purchaseToken"}]';
				document.frm.data.value = data;
				
				$.ajax({
					type: "POST",
					url: "<c:url value="http://14.63.162.53:8080/u_magazine_admin/API/v1_0/purchaseUpload" />",
					dataType: "json",
					async: false,
					data: $(document.frm).serialize(),
					success: function(data){
						if(data.returnCode == "000"){
							location.href = link;
						}else{
							alert(data.returnMessage);
						}
					},
					beforeSend: function(){
					},
					error: function(jqXHR, textStatus, errorThrown){
						//alert(jqXHR.responseText); //에러 페이지 내용
						alert("오류가 발생하였습니다.\n관리자에게 문의 바랍니다.");
						throw errorThrown;
					},
					complete: function(){
					}
				 });
				
			}
			
			function goEvent4(eventIdx, link){
				//var data = '[{"cmd":"detailedEvent","eventIdx":'+eventIdx+',"actionTime":"now"}]';
				//var data = '[{"cmd":"viewLog","contIdx":1,"fileIdx":2,"actionTime":"20130425173000","logData":[{"PageIndex":"1", "ViewCount":"1", "ViewDuration":"20136548","ScrapCount":"0","EmailCount":"0","TwitterCount":"1","FacebookCount":"1"}, {"PageIndex":"1", "ViewCount":"1", "ViewDuration":"20136548","ScrapCount":"0","EmailCount":"0","TwitterCount":"1","FacebookCount":"1"}]}]';
				var data = '[{"orderId":"data_orderid","packageName":"data_packageName","productId":"data_productId","purchaseTime" : "data_purchaseTime","purchaseState":"3","developerPayload":"data_developerPayload","purchaseToken":"data_purchaseToken"}]';
				//var data = '[{"orderId":"data_orderid","packageName":"data_packageName","productId":"data_productId","purchaseTime":"data_purchaseTime","purchaseState":"A","developerPayload":"data_developerPayload","purchaseToken":"data_purchaseToken"}]';
				document.frm.data.value = data;
				
				$.ajax({
					type: "POST",
					url: "<c:url value="/API/v1_0/purchaseUpload" />",
					dataType: "json",
					async: false,
					data: $(document.frm).serialize(),
					success: function(data){
						if(data.returnCode == "000"){
							location.href = link;
						}else{
							alert(data.returnMessage);
						}
					},
					beforeSend: function(){
					},
					error: function(jqXHR, textStatus, errorThrown){
						//alert(jqXHR.responseText); //에러 페이지 내용
						alert("오류가 발생하였습니다.\n관리자에게 문의 바랍니다.");
						throw errorThrown;
					},
					complete: function(){
					}
				 });
				
			}
		</script>
	</head>
	<body>
		<div class="contWrap">
			<div class="rollingWrap">
				<div class="rolling">
					<ul class="bxslider">
						<c:forEach var="event" items="${eventList}">
							<c:forEach var="eventFile" items="${eventFileList}">
								<c:if test="${event.idx eq eventFile.eventIdx}">
									<c:if test="${eventFile.fileType eq 'bigBanner'}">
										<c:set var="bigBanner" value="${eventFile.fileUrl }" />
									</c:if>
									<c:if test="${eventFile.fileType eq 'smallBanner'}">
										<c:set var="smallBanner" value="${eventFile.fileUrl }" />
									</c:if>
									<c:if test="${eventFile.fileType eq 'detail'}">
										<c:set var="detail" value="${eventFile.fileUrl }" />
									</c:if>
								</c:if>
							</c:forEach>
							<li><img src="${bigBanner}" height="120px" onclick="javascript:detail('${detail}','${event.linkUrl}');"></li>
						</c:forEach>
					</ul>
				</div>
			</div>
			<div class="listWrap">
				<c:forEach var="event" items="${eventList}" varStatus="stat">
					<c:forEach var="eventFile" items="${eventFileList}">
						<c:if test="${event.idx eq eventFile.eventIdx}">
							<c:if test="${eventFile.fileType eq 'bigBanner'}">
								<c:set var="bigBanner" value="${eventFile.fileUrl }" />
							</c:if>
							<c:if test="${eventFile.fileType eq 'smallBanner'}">
								<c:set var="smallBanner" value="${eventFile.fileUrl }" />
							</c:if>
							<c:if test="${eventFile.fileType eq 'detail'}">
								<c:set var="detail" value="${eventFile.fileUrl }" />
							</c:if>
						</c:if>
					</c:forEach>
					<c:choose>
						<c:when test="${event.emblem eq 'N'}"><c:url var="emblemImgUrl" value="${dirImages}/icon_event_new.png" /></c:when>
						<c:when test="${event.emblem eq 'E'}"><c:url var="emblemImgUrl" value="${dirImages}/icon_event_event.png" /></c:when>
						<c:when test="${event.emblem eq 'S'}"><c:url var="emblemImgUrl" value="${dirImages}/icon_event_special.png" /></c:when>
						<c:when test="${event.emblem eq 'H'}"><c:url var="emblemImgUrl" value="${dirImages}/icon_event_hot.png" /></c:when>
						<c:when test="${event.emblem eq 'X'}"><c:url var="emblemImgUrl" value="" /></c:when>
					</c:choose>
					<a id="detailImg${event.idx}" href="#detailImg" class="eventImgWrap <c:choose><c:when test="${stat.index%2 eq 0}">left</c:when><c:otherwise>right</c:otherwise></c:choose>" onclick="javascript:detail('${detail}','${event.linkUrl}', ${event.idx});">
						<img class="eventImg" src="${smallBanner}">
						<c:if test="${not empty emblemImgUrl && event.emblem ne 'X'}"><img class="emblem" src="${emblemImgUrl}"></c:if>
					</a>
				</c:forEach>
			</div>
			<img id="detailImg" class="detailImg" src="" style="display: none;" />
		</div>
		<form name="frm" method="post" style="display: none;">
			<input type="hidden" name="device_id" value="${param.device_id}" />
			<input type="hidden" name="model" value="${param.model}" />
			<input type="hidden" name="os_ver" value="${param.os_ver}" />
			<input type="hidden" name="lcd_size" value="${param.lcd_size}" />
			<input type="hidden" name="store_type" value="${param.store_type}" />
			<input type="hidden" name="app_id" value="${param.app_id}" />
			<input type="hidden" name="app_ver" value="${param.app_ver}" />
			<input type="hidden" name="os_gubun" value="android" />
			<input type="hidden" name="data" />			
		</form>
	</body>
</html> 